package com.mzw.huaxiarealestatebackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.ProjectProcess;
import com.mzw.huaxiarealestatebackend.dao.ProjectProcessDao;
import com.mzw.huaxiarealestatebackend.service.ProjectProcessService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (ProjectProcess)表服务实现类
 *
 * @author makejava
 * @since 2023-12-22 00:03:04
 */
@Service("projectProcessService")
public class ProjectProcessServiceImpl implements ProjectProcessService {
    @Resource
    private ProjectProcessDao projectProcessDao;

    /**
     * 通过ID查询单条数据
     *
     * @param pcsNo 主键
     * @return 实例对象
     */
    @Override
    public ProjectProcess queryById(Integer pcsNo) {
        QueryWrapper<ProjectProcess> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pcs_no", pcsNo);
        ProjectProcess projectProcess = projectProcessDao.selectOne(queryWrapper);
        return projectProcess;
    }

    /**
     * 分页查询
     * @param current    当前页码
     * @param size      分页大小
     * @return
     */
    @Override
    public BackPage<ProjectProcess> queryByPage(int current, int size) {
        BackPage<ProjectProcess> backPage= new BackPage<>();
        //创建Page对象，传递两个参数：当前页    每页显示记录数
        Page<ProjectProcess> page = new Page<>(current,size);
        //调用mp方法实现分页
        projectProcessDao.selectPage(page,null);
        //IPage<User> pageModel = userMapper.selectPage(page,null);
        backPage.setContentList(page.getRecords());
        backPage.setCurrentPage(page.getCurrent());
        backPage.setTotalPage(page.getPages());
        backPage.setTotalNum(page.getTotal());
        return backPage;
    }

    /**
     * 新增数据
     *
     * @param projectProcess 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(ProjectProcess projectProcess) {
        int insert = this.projectProcessDao.insert(projectProcess);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param projectProcess 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(ProjectProcess projectProcess) {

        int update = this.projectProcessDao.update(projectProcess);
        return update > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param pcsNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer pcsNo) {
        return this.projectProcessDao.deleteById(pcsNo) > 0;
    }
}
